package com.qhit.jdbc;

import com.qhit.jdbc.bean.Student;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * TODO
 *
 * @author 村头老杨头
 * @version 1.0
 * @date 2021/9/24 8:28
 */
public class App {
    public static void main(String[] args) {
        //创建学生对象
        Student student = new Student();

        student.setSname("张三");

        try {
            //Student类的类对象
            Class<Student> aClass = (Class<Student>) Class.forName("com.qhit.jdbc.bean.Student");


            Field[] fields = aClass.getDeclaredFields();
            for (Field field : fields) {
                if(field.getName().equals("sname")){
//                    field.setAccessible(true);
//                    field.set(student,"李四");
                }
                System.out.println(field.getName()+"\t"+field.getType());
            }
            Method setSname = aClass.getMethod("setSname", String.class);
            setSname.invoke(student,"王五");

            Student student1 = aClass.newInstance();
            System.out.println("学生姓名："+student.getSname());
//            Class<Student> studentClass = Student.class;
//            Class<? extends Student> aClass1 = student.getClass();
        } catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | InstantiationException e) {
            e.printStackTrace();
        }
    }
}
